package com.scorpio.web.controller.agentuser;

import com.alibaba.fastjson.JSONObject;
import com.scorpio.agentuser.service.AgentIncomeService;
import com.scorpio.agentuser.service.AgentPayUserService;
import com.scorpio.agentuser.service.AgentRegUserService;
import com.scorpio.agentuser.service.AgentUserService;
import com.scorpio.common.core.controller.BaseController;
import com.scorpio.common.core.domain.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
@RequestMapping("/agent/statistics")
public class AgentStatisticsController extends BaseController {


    @Autowired
    private AgentRegUserService regUserService;

    @Autowired
    private AgentPayUserService payUserService;

    @Autowired
    private AgentIncomeService incomeService;

    @Autowired
    private AgentUserService agentUserService;

    @GetMapping("statisticsAll")
    public Result statisticsAll(Long agentId, Integer type, Date quertDate) {
        JSONObject json = new JSONObject();
        json.put("regOption", regUserService.statistics(agentId, type, quertDate));
        json.put("regOptionPie", regUserService.statisticsPie(agentId, type, quertDate));
        json.put("incomeOption", incomeService.statistics(agentId, type, quertDate));
        json.put("incomeOptionPie", incomeService.statisticsPie(agentId, type, quertDate));
        json.put("payOption", payUserService.statistics(agentId, type, quertDate));
        json.put("payOptionPie", payUserService.statisticsPie(agentId, type, quertDate));
        if (agentId != null) {
            json.put("agent", agentUserService.selectDetailsById(agentId));
        }
        return Result.success(json);
    }

    @GetMapping("regStatistics")
    public Result regStatistics(Long agentId, Integer type, Date quertDate) {
        JSONObject json = new JSONObject();
        json.put("agnet", null);
        json.put("option", regUserService.statistics(agentId, type, quertDate));
        json.put("probably", regUserService.userProbably(agentId));
        if (agentId != null) {
            json.put("agnet", agentUserService.selectDetailsById(agentId));
        }
        return Result.success(json);
    }

    @GetMapping("incomeStatistics")
    public Result incomeStatistics(Long agentId, Integer type, Date quertDate) {
        JSONObject json = new JSONObject();
        json.put("agnet", null);
        json.put("option", incomeService.statistics(agentId, type, quertDate));
        if (agentId != null) {
            json.put("agnet", agentUserService.selectDetailsById(agentId));
        }
        return Result.success(json);
    }

    @GetMapping("payStatistics")
    public Result payStatistics(Long agentId, Integer type, Date quertDate) {
        JSONObject json = new JSONObject();
        json.put("agnet", null);
        json.put("option", payUserService.statistics(agentId, type, quertDate));
        if (agentId != null) {
            json.put("agnet", agentUserService.selectDetailsById(agentId));
        }
        return Result.success(json);
    }
}
